﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace client.app.gui2
{
    /// <summary>
    /// CheckBox1.xaml 的交互逻辑
    /// </summary>
    public partial class CheckBox1 : UserControl, IUInput
    {
        public event RoutedEventHandler Checked;

        public bool StopEvent
        {
            get { return true; }
        }
        public string Text
        {
            get { return tbText.Text; }
            set
            {
                tbText.Text = value;
                this.UpBeginDraw();
            }
        }
        public bool IsChecked
        {
            get { return ck.IsChecked == true; }
            set { ck.IsChecked = value; }
        }

        public CheckBox1()
        {
            InitializeComponent();

            ck.Checked += new RoutedEventHandler(ck_Checked);
            ck.Unchecked += new RoutedEventHandler(ck_Unchecked);
            MouseLeftButtonDown += new MouseButtonEventHandler(CheckBox1_MouseLeftButtonDown);
            IsEnabledChanged += new DependencyPropertyChangedEventHandler(CheckBox1_IsEnabledChanged);
        }

        void ck_Checked(object sender, RoutedEventArgs e)
        {
            brDot.Visibility = Visibility.Visible;
            if (Checked != null)
            {
                Checked(this, new RoutedEventArgs());
            }
            this.UpBeginDraw();
        }
        void ck_Unchecked(object sender, RoutedEventArgs e)
        {
            brDot.Visibility = Visibility.Collapsed;
            if (Checked != null)
            {
                Checked(this, new RoutedEventArgs());
            }
            this.UpBeginDraw();
        }

        void CheckBox1_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Opacity = IsEnabled ? 1 : .3;
        }
        void CheckBox1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ck.IsChecked = !ck.IsChecked;
        }

        public void CallMouseEvent(MouseEventType type, Point point)
        {
            if (type == MouseEventType.LEFT_DOWN)
            {
                ck.IsChecked = !ck.IsChecked;
                if (Checked != null)
                {
                    Checked(this, new RoutedEventArgs());
                }
            }
        }
    }
}
